package pl.leader100.rest;

import javax.ws.rs.GET;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Request;
import javax.ws.rs.core.UriInfo;

import pl.leader100.rest.data.DocDao;
import pl.leader100.rest.data.Situation;

// The class registers its methods for the HTTP GET request using the @GET annotation. 
// Using the @Produces annotation, it defines that it can deliver several MIME types,
// text, XML and HTML. 

// The browser requests per default the HTML MIME type.

//Sets the path to base URL + /hello

public class ListSituation {
	@Context
	UriInfo uriInfo;
	@Context
	Request request;

	String month;
	String locale;
	String year = "2011/2012";
	String course = "junior_leader_r1";
	String field = "competency";
	
	public ListSituation(UriInfo uriInfo, Request request, String month,
			String locale) {
		this.uriInfo = uriInfo;
		this.request = request;
		this.month = month;
		this.locale = locale;
	}

	public ListSituation(UriInfo uriInfo, Request request, String month,
			String locale, String year, String course) {
		this.uriInfo = uriInfo;
		this.request = request;
		this.month = month;
		this.locale = locale;
		this.year = year;
		this.course = course;
	}

	// This method is called if TEXT_PLAIN is request
	@GET
	@Produces(MediaType.TEXT_PLAIN)
	public String sayPlainTextHello() {
		return "no way";
	}

	// Application integration
	@GET
	@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
	public Situation getSituation() {

		String[] situations = DocDao.GetInstance().getSituations(
				field, Integer.parseInt(month), locale, year, course);

		Situation s = new Situation(course, month, locale, situations, null);

		if (s == null)
			throw new RuntimeException("Get: Situation with " + " " + month + " "
					+ locale + " not found");
		return s;
	}

	// For the browser
	/*
	 * @GET
	 * 
	 * @Produces(MediaType.TEXT_XML) public List<Doc> getTodoHTML() { List<Doc>
	 * docs = DocDao.GetInstance().getSituations(month, locale, year, course);
	 * if (docs == null) throw new RuntimeException("Get: Doc with " + " " +
	 * month + " " + locale + " not found"); return docs; }
	 */

}
